class Tool {
  constructor() {}
  log(...arg) {
    console.log(arg.toString());
  }
  // 返回随机数
  random(min, max) {
    if (max == null) {
      max = min;
      min = 0;
    }
    return min + Math.floor(Math.random() * (max - min + 1));
  }
  // 数组乱序
  shuffle(obj) {
    let length = obj.length;
    let shuffled = Array(length);
    for (let index = 0, rand; index < length; index++) {
      rand = this.random(0, index);
      if (rand !== index) shuffled[index] = shuffled[rand];
      shuffled[rand] = obj[index];
    }
    return shuffled;
  }
  formatKey(n) {
    var a = n[0].comic_name;
    var t = n,
      s = 0,
      o = t.length,
      i = function (n) {
        return 17 * n.length;
      },
      l = i(a)
    for (; s < o; s++) {
      var c = t[s].comic_name;
      t[s].w = i(c);
    }
    t.sort(function (n, a) {
      return a.w - n.w;
    });
    var d = [],
      u = window.innerWidth - 30,
      h = u - (l + 14);
    for (var m = 0; m < 3; m++) {
      for (var p = 0; p < t.length;) {
        var f = t[p];
        if (h <= 0) break;
        f.w + 14 < h ?
          (d.push(f), t.splice(p, 1), (h -= f.w + 14)) :
          p++;
      }
      h = u;
    }
    return d;
  }
}
export default new Tool;
